package org.crc.myvhrb.exception;

import org.crc.myvhrb.model.RespBean;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.sql.SQLException;
import java.sql.SQLIntegrityConstraintViolationException;

/**
 * CRC
 * 2021/8/6
 */
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(SQLException.class)
    public RespBean sqlException(SQLException e){
        if (e instanceof SQLIntegrityConstraintViolationException){
            RespBean.error("该数据有关联数据，操作失败！");
        }
        return RespBean.error(e.getLocalizedMessage());
    }


}
